<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0,user-scalable=no,minimal-ui">
    <title>蜜雪冰城</title>
    <link rel="icon" href="../../back/images/icons/蜜雪logo.svg">
    <!--不同屏幕尺寸根字体设置-->
    <script src="../js/base.js"></script>
    <!--element-ui的样式-->
    <link rel="stylesheet" href="../../back/plugins/element-ui/index.css" />
    <!--引入vant样式-->
    <link rel="stylesheet" href="../styles/vant.min.css"/>
    <!-- 引入样式  -->
    <link rel="stylesheet" href="../styles/user.css" />
    <!--本页面内容的样式-->
    <link rel="stylesheet" href="../styles/index.css" />

    <link rel="stylesheet" href="../styles/main.css" />
    <style>
       .el-dialog__wrapper{
            height: 100%!important;
        }
       .order_item{
           font-size: 12rem;
           width: 27%;
           text-align: center;
           height: 40rem;
           display: inline-block;
       }
    </style>
</head>
<body>
<div id="user" class="app" v-loading="loading">
    <div class="divHead">
        <div class="divTitle">
            <i class="el-icon-arrow-left" @click="goBack"></i>个人中心
        </div>
        <div class="divUser">
            <el-image :src="imgPathConvert(form.image)" >
                <div slot="error" class="image-slot">
                                <img style="       width: 48rem;
    margin: 12rem 18rem 7rem 10rem;
    height: 48rem;" src="../../back/images/icons/login_false.jpg"/>
                </div>
            </el-image>
            <div class="desc">
                <div class="divName" @click="toLoginPage">{{form.userName}}</div>
                <div class="divPhone">手机号:{{form.userPhone}}</div>
            </div>
        </div>
    </div>
    <div class="divContent">
        <div class="divLinks">
            <div class="item" @click="toAddressPage">
               <div> <span>我的订单</span>
               <span style="    font-size: 12rem;
    color: #787878;"> <i style="margin-right: 10rem">查看全部</i><i class="el-icon-arrow-right"></i></span>
               </div>
            </div>
            <div style="    margin: -11rem 0px 0px 24rem;
    font-size: 35rem;
    color: rgb(120 120 120);">
                <span style="width: 27%;margin-left: -8rem;" class="el-icon-sell"></span>
                <span style="width: 25%" class="el-icon-truck"></span>
                <span style="width: 24%" class="el-icon-shopping-cart-2"></span>
                <span style="" class="el-icon-edit-outline"></span>
            </div>
            <div>
                <span class="order_item" style="margin-left: -12rem">待付款</span>
                <span class="order_item">待分享</span>
                <span class="order_item">待收货</span>
                <span class="order_item" style="width: 28rem;margin-left: 18rem">评价</span>
            </div>
            <div class="divSplit"></div>
        </div>
        <div class="divOrders" v-if="order[0]">
            <div class="title" style="margin-right: 3rem">最新订单</div>
            <div class="timeStatus">
                <span>{{order[0].orderTime}}</span>
                <span>{{getStatus(order[0].status)}}</span>
                <!-- <span>正在派送</span> -->
            </div>
            <div class="dishList">
                <div v-for="(item,index) in order[0].orderDetails" :key="index" class="item">
                    <span>{{item.name}}</span>
                    <span>x{{item.number}}</span>
                </div>
            </div>
            <div class="result">
                <span>共{{order[0].sumNum}} 件商品,实付</span>
                <span class="price">￥{{order[0].amount}}</span>
            </div>
            <div class="btn" v-if="order[0].status === 4">
                <div class="btnAgain" @click="addOrderAgain">再来一单</div>
            </div>
        </div>
        <div class="quitLogin" @click="toPageLogin">
            退出登录
        </div>
        <div style="height: 61rem"></div>
    </div>
</div>
<!-- 开发环境版本，包含了有帮助的命令行警告 -->
<script src="../../back/plugins/vue/vue.js"></script>
<!-- 引入组件库 -->
<script src="../../back/plugins/element-ui/index.js"></script>
<!-- 引入vant样式 -->
<script src="../js/vant.min.js"></script>
<!-- 引入axios -->
<script src="./../js/base.js"></script>
<!-- 引入axios -->
<script src="../../back/plugins/axios/axios.min.js"></script>
<script src="./../js/request.js"></script>
<script src="./../api/order.js"></script>
<script src="./../api/login.js"></script>
<script src="../js/common.js"></script>
</body>
<script>
    new Vue({
        el:"#user",
        data(){
            return {
                form:{
                    userName:'请先登录',
                    userPhone:'',
                    code:'',
                    image:'',
                },
                msgFlag:false,
                loading:false,
                order:[{
                    orderTime:'',//下单时间
                    status:undefined,//订单状态 1已结账，2未结账，3已退单，4已完成，5已取消
                    orderDetails:[{
                        name:'',//菜品名称
                        number:undefined,//数量
                    }],//明细
                    amount:undefined,//实收金额
                    sumNum:0,//菜品总数
                }],
            }
        },
        computed:{},
        created(){
            this.userPhone =sessionStorage.getItem("userPhone")
            this.initData()
        },
        mounted(){},

        methods:{
            goBack(){
                history.go(-1)
            },
            //网络图片路径转换
            imgPathConvert(path){
                return imgPath(path)
            },
            //跳转到去结算界面
            toAddOrderPage(){
                if(this.cartData.length > 0){
                    window.requestAnimationFrame(()=>{
                        window.location.href ='/front/page/add-order.html'
                    })
                }
            },
            toLoginPage(){
                if (this.form.userName==='请先登录'){
                    this.loading=true
                    setTimeout(()=>{
                        this.loading=false
                        window.requestAnimationFrame(()=>{
                            window.location.href= '/front/page/login.html'
                        },500)
                    })

                }
            },
            toAddressPage(){
                window.requestAnimationFrame(()=>{
                    window.location.href = '/front/page/address.html'
                })
            },
            toOrderPage(){
                window.requestAnimationFrame(()=>{
                    window.location.href = '/front/page/order.html'
                })
            },
            initData(){
                this.getLatestOrder()
            },
            async getLatestOrder(){
                const params = {
                    page:1,
                    pageSize:1
                }
                const res = await orderPagingApi(params)
                if(res.code === 1){
                    this.order = res.data.records
                    if(this.order && this.order[0].orderDetails){
                        let number = 0
                        this.order[0].orderDetails.forEach(item=>{
                            number += item.number
                        })
                        this.order[0].sumNum = number
                    }
                }else{
                    this.$notify({ type:'warning', message:res.msg});
                }
            },
            getStatus(status){
                let str = ''
                switch(status){
                    case 1:
                        str =  '待付款'
                        break;
                    case 2:
                        str =  '正在派送'
                        break;
                    case 3:
                        str =  '已派送'
                        break;
                    case 4:
                        str =  '已完成'
                        break;
                    case 5:
                        str =  '已取消'
                        break;

                }
                return str
            },
            async addOrderAgain(){
                const res = await orderAgainApi({id:this.order[0].id})
                if(res.code === 1){
                    window.requestAnimationFrame(()=>{
                        window.location.href = '/front/index.html'
                    })
                }else{
                    this.$notify({ type:'warning', message:res.msg});
                }
            },
            async toPageLogin(){
                const res = await loginoutApi()
                if(res.code === 1){
                    window.requestAnimationFrame(()=>{
                        window.location.href = '/front/page/login.html'
                    })
                }else{
                    this.$notify({ type:'warning', message:res.msg});
                }
            }

        }
    })
</script>
</html>
